*******************************************	   
************* TABLE A4 Analysis excluding larger groups
*******************************************	  

clear all
clear matrix
set more off
set matsize 11000

// Load dataset
use "~/Dropbox/Replication_MVC/Datasets/datasets_analysis/panel_excombatientes.dta", clear 

// Calculate the count of members in each group and save it to a temporary dataset
tempfile membercount
sort year wartimenetwork
collapse (count) id, by(year wartimenetwork)
rename id members_total
save "`membercount'", replace

// Load the original dataset
use "~/Dropbox/Replication_MVC/Datasets/datasets_analysis/panel_excombatientes.dta", clear 

// Merge the member count information back into the original dataset
merge m:1 year wartimenetwork using "`membercount'"
drop _merge

// Remove the temporary dataset
erase "`membercount'"

eststo clear
set more off

* less than 1000
reghdfe diffcaptures_f gold_shock_r mean_gold_shock_r age female black indigenous c.time_t##i.region c.pobreza##c.time_t c.pobl_tot##c.time_t c.disbogota##c.time_t c.paved_roads##c.time_t if members_total<=1000, absorb(wartimenetwork year origmun) vce(cluster wartimenetwork)
estadd local ALLFE = "$\checkmark$"
estadd local TT = "$\checkmark$"
estadd local MT = "$\checkmark$"
estadd local BC = "$\checkmark$"
estadd local CO = "$\checkmark$"
summ diffcaptures_f if e(sample) ==1
estadd local meanDep = trim("`: display %12.4fc `r(mean)''")
estadd local SDDep = trim("`: display %12.4fc `r(sd)''")
eststo

* less than 500
reghdfe diffcaptures_f gold_shock_r mean_gold_shock_r age female black indigenous c.time_t##i.region c.pobreza##c.time_t c.pobl_tot##c.time_t c.disbogota##c.time_t c.paved_roads##c.time_t if members_total<=500, absorb(wartimenetwork year origmun) vce(cluster wartimenetwork)
estadd local ALLFE = "$\checkmark$"
estadd local TT = "$\checkmark$"
estadd local MT = "$\checkmark$"
estadd local BC = "$\checkmark$"
estadd local CO = "$\checkmark$"
summ diffcaptures_f if e(sample) ==1
estadd local meanDep = trim("`: display %12.4fc `r(mean)''")
estadd local SDDep = trim("`: display %12.4fc `r(sd)''")
eststo

* less than 250
reghdfe diffcaptures_f gold_shock_r mean_gold_shock_r age female black indigenous c.time_t##i.region c.pobreza##c.time_t c.pobl_tot##c.time_t c.disbogota##c.time_t c.paved_roads##c.time_t if members_total<=250, absorb(wartimenetwork year origmun) vce(cluster wartimenetwork)
estadd local ALLFE = "$\checkmark$"
estadd local TT = "$\checkmark$"
estadd local MT = "$\checkmark$"
estadd local BC = "$\checkmark$"
estadd local CO = "$\checkmark$"
summ diffcaptures_f if e(sample) ==1
estadd local meanDep = trim("`: display %12.4fc `r(mean)''")
estadd local SDDep = trim("`: display %12.4fc `r(sd)''")
eststo

* less than 100
reghdfe diffcaptures_f gold_shock_r mean_gold_shock_r age female black indigenous c.time_t##i.region c.pobreza##c.time_t c.pobl_tot##c.time_t c.disbogota##c.time_t c.paved_roads##c.time_t if members_total<=100, absorb(wartimenetwork year origmun) vce(cluster wartimenetwork)
estadd local ALLFE = "$\checkmark$"
estadd local TT = "$\checkmark$"
estadd local MT = "$\checkmark$"
estadd local BC = "$\checkmark$"
estadd local CO = "$\checkmark$"
summ diffcaptures_f if e(sample) ==1
estadd local meanDep = trim("`: display %12.4fc `r(mean)''")
estadd local SDDep = trim("`: display %12.4fc `r(sd)''")
eststo

esttab est* using "~/Dropbox/Replication_MVC/Paper_tables/TableA4_panelA.tex", se ///
	   star(* 0.10 ** 0.05 *** 0.01 ) ///
	   stats(meanDep SDDep N ALLFE TT BC CO, fmt(%12.4fc %12.4fc  %12.0fc %12.0fc %12.0fc  %12.0fc %12.0fc) ///
	 label("\small Mean of Outcome" "\small S.D of Outcome" "Observations" "\small Municipality, Year, and Group FE" "\small Time Trends" "\small Region $\times$ Year" ///
	 "\small Municipality Characteristics TT" "\small Individual Covariates" )) ///
	   varlabels(gold_shock_r "Economic Shock" mean_gold_shock_r "Average Shock" ) ///
	   ti("Economic Shock and Peer Effects for fragrant captures - Full Model results") ///	  
	   replace
	   
eststo clear
set more off

* less than 1000
reghdfe diffcaptures_f gold_shock_r mean_gold_shock_r age female black indigenous c.pobreza##c.time_t c.pobl_tot##c.time_t c.disbogota##c.time_t c.paved_roads##c.time_t if members_total<=1000, absorb(wartimenetwork year origmun  c.time_t##i.region ) vce(cluster wartimenetwork)
nlcom _b[mean_gold_shock_r]/(_b[gold_shock_r] + _b[mean_gold_shock_r]), post
eststo

* less than 500
reghdfe diffcaptures_f gold_shock_r mean_gold_shock_r age female black indigenous c.pobreza##c.time_t c.pobl_tot##c.time_t c.disbogota##c.time_t c.paved_roads##c.time_t if members_total<=500, absorb(wartimenetwork year origmun  c.time_t##i.region ) vce(cluster wartimenetwork)
nlcom _b[mean_gold_shock_r]/(_b[gold_shock_r] + _b[mean_gold_shock_r]), post
eststo

* less than 250
reghdfe diffcaptures_f gold_shock_r mean_gold_shock_r age female black indigenous c.pobreza##c.time_t c.pobl_tot##c.time_t c.disbogota##c.time_t c.paved_roads##c.time_t if members_total<=250, absorb(wartimenetwork year origmun  c.time_t##i.region ) vce(cluster wartimenetwork)
nlcom _b[mean_gold_shock_r]/(_b[gold_shock_r] + _b[mean_gold_shock_r]), post
eststo

* less than 100
reghdfe diffcaptures_f gold_shock_r mean_gold_shock_r age female black indigenous c.pobreza##c.time_t c.pobl_tot##c.time_t c.disbogota##c.time_t c.paved_roads##c.time_t if members_total<=100, absorb(wartimenetwork year origmun  c.time_t##i.region ) vce(cluster wartimenetwork)
nlcom _b[mean_gold_shock_r]/(_b[gold_shock_r] + _b[mean_gold_shock_r]), post
eststo

esttab est* using "~/Dropbox/Replication_MVC/Paper_tables/TableA4_panelB.tex", se ///
	   star(* 0.10 ** 0.05 *** 0.01 ) ///
	   stats(meanDep N, fmt(%12.4fc %12.0fc)) ///
	   keep(_nl_1 ) ///
	   varlabels( _nl_1 "Peer Effect") ///
	   ti("Economic Shock and Peer Effects") ///	  
	   replace
